<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;

class BaseController extends Controller
{
    public function apiResolveList($data, int $page, int $limit)
    {
        $result = (object)[
            'status' => 'success',
            'page' => $page,
            'limit' => $limit,
            'total' => count($data),
            'dataSize' => sizeof($data),
            'data' => $data
        ];
        return json_encode($result);
    }

    public function apiResolveObject($data)
    {
        $result = (object)[
            'status' => 'success',
            'data' => $data
        ];
        return json_encode($result);
    }

    public function apiResolveError(string $error)
    {
        $result = (object)[
            'status' => 'failed',
            'error' => $error
        ];
        return json_encode($result);
    }
}
